<%@ include file="/common/taglibs.jsp" %>
<link rel="stylesheet" type="text/css" href="<c:url value='/css/jquery/flexigrid.pack.css' />" />
<script type="text/javascript" src="<c:url value='/js/jquery/flexigrid.pack.js' />"></script>
<script type="text/javascript" src="<c:url value='/js/util.js'/>"></script>
<script type="text/javascript" src="<c:url value='/js/payment-line-item.js'/>"></script>
<script type="text/javascript" src="<c:url value='/js/jquery/jquery.numeric.js'/>"></script>
<script type="text/javascript" src="<c:url value='/js/jquery/jquery.formatCurrency-1.4.0.pack.js'/>"></script>
<link href="<c:url value='/css/dhtmlxcombo_paylineitem.css' />"	rel="stylesheet" type="text/css" />
  
<script type="text/javascript">
	$(document).ready(function() {
		$('#pageTitle').text('<spring:message code="editPaymentrequest.heading" />');
		<c:if test="${showPaymentLineItems}">
		var arr_projects = new Array();
		<c:forEach items="${cipeProjects}" var="project" varStatus="status">
			var project${status.index} = new Object();
			project${status.index}.id = '${project.id}';
			project${status.index}.projectId = '${project.projectId}';
			project${status.index}.projectType = '${project.projectTypeDesc}';
			project${status.index}.title = '${project.escapedTitle}';
			project${status.index}.status = '${project.status}';
			project${status.index}.region = '${project.escapedRegion}';
			project${status.index}.country = '${project.escapedCountry}';
			project${status.index}.acronym = '${project.escapedAcronym}';
			project${status.index}.formattedStartDate = '${project.formattedProjectStartDate}';
			project${status.index}.formattedEndDate = '${project.formattedProjectEndDate}';
			project${status.index}.partnerName = '${project.escapedPartnerName}';
			project${status.index}.override = '${project.budgetOverride}';
			project${status.index}.remainingFunds = ${project.remainingFundsPRExcluded};
			project${status.index}.displayName = '${project.displayName}';
			arr_projects[${status.index}] = project${status.index};
		</c:forEach>
		var arr_account_codes = new Array();
		<c:forEach items="${accountCodes}" var="accountCode" varStatus="status">
			var accountCode${status.index} = new Object();
			accountCode${status.index}.id = '${accountCode.id}';
			accountCode${status.index}.code = '${accountCode.code}';
			accountCode${status.index}.accountStatus = '${accountCode.accountStatus}';
			accountCode${status.index}.description = '<c:out value="${accountCode.escapedDescription}" />';
			accountCode${status.index}.displayName = '<c:out value="${accountCode.displayName}" />';
			arr_account_codes[${status.index}] = accountCode${status.index};
		</c:forEach>
		var arr_lineItems = new Array();
		<c:forEach items="${paymentrequest.lineItemBeans}" var="item" varStatus="status">
			var item${status.index} = new Object();
			item${status.index}.id = '${item.id}';
			item${status.index}.accountCodeId = '${item.accountCodeId}';
			item${status.index}.cipeProjectId = '${item.cipeProjectId}';
			item${status.index}.lineItemNumber = '${item.lineItemNumber}';
			item${status.index}.prevAmount = <c:out value="${item.prevAmount}" default="0.0" />;
			item${status.index}.amount = <c:out value="${item.amount}" default="0.0" />;
			arr_lineItems[${status.index}] = item${status.index};
		</c:forEach>
		
		var tabIndex = parseInt($('#specialInstructions').attr('tabindex'));

		var paymentLineItem = new com.cipe.cmrs.model.PaymentLineItem('paymentLineItems', arr_projects, arr_account_codes, arr_lineItems, tabIndex, function(totalAmount) {
			$('#amount').val(totalAmount);
			$('#amount').formatCurrency('#amountLabel',{colorize: true, negativeFormat: '(-%s%n)'});
		});
		</c:if>
		$('#amount').formatCurrency('#amountLabel',{colorize: true, negativeFormat: '(-%s%n)'});
		
		$.validator.addMethod("drop_down_required", function(value, element) {
			return (value != "");
		}, "Please select an option.");
		
		$("#editPaymentrequestForm").validate({
			rules : {
				paymentTypeId : {
					drop_down_required : true
				},
				paymentMethod : {
					drop_down_required : true
				},
				payeeId : {
					drop_down_required : true
				},
				purposeOfExpenditure : {
					required : true
				}
			}
		});
		$.validator.addMethod("valueNotEquals", function (value, element, arg) {
			var con=$(element).next().attr("name");	
			if(con.substring(0,13)!='lineItemBeans')
			    return arg != value;
			else
				return true;
		}, "This field is required");
		
			$(".dhx_combo_input").rules("add", { 
	  			required:true,
	  			valueNotEquals: "Select"

			});
		
       $("#doSave").bind("click",function(){    
    		$(this).bind("ajaxSend", function(){
                $('#loading').remove();
		$(this).after("<img  id='loading' src='<c:url value='/images/ajax-loader.gif'/>' alt='loading' />");

		 }).bind("ajaxComplete", function(){

			$('#loading').remove();

		 });


      		var t= setTimeout(function(){
      		$('.dhx_combo_input:not(.payment-line-item-project-id .dhx_combo_input)').click();
      		$('.input-full-width text_grey').click();
      		},300);    
      		
      	 	if($('.dhx_combo_input').eq(0).val() == 'Select' || $('.dhx_combo_input').eq(0).val() == '' ){
				 $('.dhx_combo_box ').eq(0).css("border-color", "#B50007");
				 }
		
      		 $('.dhx_combo_input').eq(0).blur(function() {
    			 if($('.dhx_combo_input').eq(0).val()!= 'Select' && $('.dhx_combo_input').eq(0).val() != ''){
    				 $('.dhx_combo_box ').eq(0).css("border-color", "#BDBCBD");
    			 }
    		 });
      		 $('.dhx_combo_input').eq(0).keypress(function(event) {
   			  if ( event.which == 8 || event.which == 9  || event.which == 40) {
   				  var inputVal = $('.dhx_combo_input').eq(0).val().length;
   			 		if(inputVal == 1){
   					 $('.dhx_combo_box ').eq(0).css("border-color", "#B50007");
   					 }else if(inputVal == 0){
   						 $('.dhx_combo_box ').eq(0).css("border-color", "#B50007");
   					}else{
   						 $('.dhx_combo_box ').eq(0).css("border-color", "#BDBCBD");
   					 }
   				   }
   			});
     		 
	 	if($('.dhx_combo_input').eq(1).val() == 'Select' || $('.dhx_combo_input').eq(1).val() == '' ){
			 $('.dhx_combo_box ').eq(1).css("border-color", "#B50007");
			 }
	
 		 $('.dhx_combo_input').eq(1).blur(function() {
 			 if($('.dhx_combo_input').eq(1).val()!= 'Select' && $('.dhx_combo_input').eq(1).val() != ''){
				 $('.dhx_combo_box ').eq(1).css("border-color", "#BDBCBD");
			 }
		 });
 		 $('.dhx_combo_input').eq(1).keypress(function(event) {
			  if ( event.which == 8 || event.which == 9  || event.which == 40) {
				  var inputVal = $('.dhx_combo_input').eq(1).val().length;
			 		if(inputVal == 1){
					 $('.dhx_combo_box ').eq(1).css("border-color", "#B50007");
					 }else if(inputVal == 0){
						 $('.dhx_combo_box ').eq(1).css("border-color", "#B50007");
					}else{
						 $('.dhx_combo_box ').eq(1).css("border-color", "#BDBCBD");
					 }
				   }
			});
  		
		 	if($('.dhx_combo_input').eq(2).val() == 'Select' || $('.dhx_combo_input').eq(2).val() == '' ){
				 $('.dhx_combo_box ').eq(2).css("border-color", "#B50007");
				 }
		
  		 $('.dhx_combo_input').eq(2).blur(function() {
  			 if($('.dhx_combo_input').eq(2).val()!= 'Select' && $('.dhx_combo_input').eq(2).val() != ''){
				 $('.dhx_combo_box ').eq(2).css("border-color", "#BDBCBD");
			 }
		 });
  		 $('.dhx_combo_input').eq(2).keypress(function(event) {
			  if ( event.which == 8 || event.which == 9  || event.which == 40) {
				  var inputVal = $('.dhx_combo_input').eq(2).val().length;
			 		if(inputVal == 1){
					 $('.dhx_combo_box ').eq(2).css("border-color", "#B50007");
					 }else if(inputVal == 0){
						 $('.dhx_combo_box ').eq(2).css("border-color", "#B50007");
					}else{
						 $('.dhx_combo_box ').eq(2).css("border-color", "#BDBCBD");
					 }
				   }
			});
  		 

      	});
		
		$("#doSaveAndAddNew").bind("click",function(){   
	
      		var t= setTimeout(function(){
      		$('.dhx_combo_input:not(.payment-line-item-project-id .dhx_combo_input)').click();
      		$('.input-full-width text_grey').click();
      		},300); 

      	 	if($('.dhx_combo_input').eq(0).val() == 'Select' || $('.dhx_combo_input').eq(0).val() == '' ){
				 $('.dhx_combo_box ').eq(0).css("border-color", "#B50007");
				 }
		
      		 $('.dhx_combo_input').eq(0).blur(function() {
    			 if($('.dhx_combo_input').eq(0).val()!= 'Select' && $('.dhx_combo_input').eq(0).val() != ''){
    				 $('.dhx_combo_box ').eq(0).css("border-color", "#BDBCBD");
    			 }
    		 });
      		 $('.dhx_combo_input').eq(0).keypress(function(event) {
   			  if ( event.which == 8 || event.which == 9  || event.which == 40) {
   				  var inputVal = $('.dhx_combo_input').eq(0).val().length;
   			 		if(inputVal == 1){
   					 $('.dhx_combo_box ').eq(0).css("border-color", "#B50007");
   					 }else if(inputVal == 0){
   						 $('.dhx_combo_box ').eq(0).css("border-color", "#B50007");
   					}else{
   						 $('.dhx_combo_box ').eq(0).css("border-color", "#BDBCBD");
   					 }
   				   }
   			});
     		 
	 	if($('.dhx_combo_input').eq(1).val() == 'Select' || $('.dhx_combo_input').eq(1).val() == '' ){
			 $('.dhx_combo_box ').eq(1).css("border-color", "#B50007");
			 }
	
 		 $('.dhx_combo_input').eq(1).blur(function() {
 			 if($('.dhx_combo_input').eq(1).val()!= 'Select' && $('.dhx_combo_input').eq(1).val() != ''){
				 $('.dhx_combo_box ').eq(1).css("border-color", "#BDBCBD");
			 }
		 });
 		 $('.dhx_combo_input').eq(1).keypress(function(event) {
			  if ( event.which == 8 || event.which == 9  || event.which == 40) {
				  var inputVal = $('.dhx_combo_input').eq(1).val().length;
			 		if(inputVal == 1){
					 $('.dhx_combo_box ').eq(1).css("border-color", "#B50007");
					 }else if(inputVal == 0){
						 $('.dhx_combo_box ').eq(1).css("border-color", "#B50007");
					}else{
						 $('.dhx_combo_box ').eq(1).css("border-color", "#BDBCBD");
					 }
				   }
			});
  		
		 	if($('.dhx_combo_input').eq(2).val() == 'Select' || $('.dhx_combo_input').eq(2).val() == '' ){
				 $('.dhx_combo_box ').eq(2).css("border-color", "#B50007");
				 }
		
  		 $('.dhx_combo_input').eq(2).blur(function() {
  			 if($('.dhx_combo_input').eq(2).val()!= 'Select' && $('.dhx_combo_input').eq(2).val() != ''){
				 $('.dhx_combo_box ').eq(2).css("border-color", "#BDBCBD");
			 }
		 });
  		 $('.dhx_combo_input').eq(2).keypress(function(event) {
			  if ( event.which == 8 || event.which == 9  || event.which == 40) {
				  var inputVal = $('.dhx_combo_input').eq(2).val().length;
			 		if(inputVal == 1){
					 $('.dhx_combo_box ').eq(2).css("border-color", "#B50007");
					 }else if(inputVal == 0){
						 $('.dhx_combo_box ').eq(2).css("border-color", "#B50007");
					}else{
						 $('.dhx_combo_box ').eq(2).css("border-color", "#BDBCBD");
					 }
				   }
			});
      	    });
		
		
		$("#creationDate").val($.format.date($("#creationDate").val(), "MM/dd/yyyy"));
		
	
			
		$('#printPaymentRequest').click(function() {
			var reportType = $('#printPaymentRequest').html();
			if($.trim(reportType) == 'Print Payment Request Form') {
				window.open("<c:url value='/secure/printPaymentRequestFormPdf.do' />?paymentRequestId=" + "${paymentrequest.id}", "_blank").focus();
			}
			if($.trim(reportType) == 'Print Partner Payment Request Form') {
			<c:choose>
				<c:when test="${showPrintPartnerPaymentRequestFormMessage}">
				var htmlString = '<div id="printPartnerPaymentRequestFormMessage"><spring:message code="editPaymentrequest.message.printPartnerPaymentRequestForm" /></div>';
				$(htmlString).dialog({
					title: 'Print Partner Payment Request Form',
					modal: true,
					height: 200,
					width: 300,
					close: function(event, ui) {
						window.open("<c:url value='/secure/printPartnerPaymentRequestPdf.do' />?paymentRequestId=" + "${paymentrequest.id}", "_blank").focus();
						$(this).dialog('destroy');
					},
					buttons: {
	 					'OK' : function() {
		 					$(this).dialog('close');
		 				}
 					}
 				});
				</c:when>
				<c:otherwise>
				window.open("<c:url value='/secure/printPartnerPaymentRequestPdf.do' />?paymentRequestId=" + "${paymentrequest.id}", "_blank").focus();
				</c:otherwise>
			</c:choose>
			}
			if($.trim(reportType) == 'Print Reclass Form') {
				window.open("<c:url value='/secure/printReclassFormPdf.do' />?paymentRequestId=" + "${paymentrequest.id}", "_blank").focus();
			}
		});
		
		$('#printWireForm').click(function() {
			window.open("<c:url value='/secure/showBankWireTransferPdf.do' />?paymentRequestId=" + "${paymentrequest.id}", "_blank").focus();
		});
		
		<c:if test="${!empty paymentrequest.id && paymentrequest.id > 0}">
			$('#processPayment').click(function() {
				var id = $('#id').val();
				loadDiv('content', 'processPaymentrequest.do?id=' + id);
			});
		</c:if>
		
		$('#newPaymentRequest').click(function() {
			loadDiv('content', 'showAddPaymentrequest.do');
		});
		
		$("#receivedFromAccountingDate").datepicker();
		$("#invoiceRequestDate").datepicker();
		$("#dateToFinanace").datepicker();
		
		$('.list-paymentrequest-link').click(function() {
			loadDiv('content', 'showPayeeList.do');
		});
		$('#instructions-link').click(function() {
			loadDiv('content', 'showInstructionsPaymentReq.do');
		});
		$('.close-button').click(function() {
				window.location = '../secure/showDashboard.do';
   		});
		
		<c:if test="${!empty paymentrequest.id && paymentrequest.id > 0}">
    		toggleViewEditMode(true);
    		
    		$('#editButton').click(function() { 
    			toggleViewEditMode(false);
    		});
    		
    		$('#cancelEditButton').click(function() {
    			var ans = confirm('Are you sure you want to cancel editing this record without saving it?');
    			if (ans) {
    				loadDiv('content', 'refreshDashboard.do');
    			}
    		});		
		</c:if>
	
		$('#save').click(function() {
		<c:choose>
			<c:when test="${showPaymentLineItems}">
			if(paymentLineItem.has6570or6571AccountCode()) {
    			open6570VerifyDialog(function(verified) {
    				$('#sixFiveSeventyVerify').prop('checked', verified);
    				$('#doSave').click();
    			});
			} else {
				$('#sixFiveSeventyVerify').prop('checked', false);
				$('#doSave').click();
			}
			</c:when>
			<c:otherwise>
			$('#sixFiveSeventyVerify').prop('checked', false);
			$('#doSave').click();
			</c:otherwise>
		</c:choose>
		});
		
		$('#saveAndAddNew').click(function(){
		<c:choose>
			<c:when test="${showPaymentLineItems}">
			if(paymentLineItem.has6570or6571AccountCode()) {
    			open6570VerifyDialog(function(verified) {
    				$('#sixFiveSeventyVerify').prop('checked', verified);
    				$('#doSaveAndAddNew').click();
    			});
			} else {
				$('#sixFiveSeventyVerify').prop('checked', false);
				$('#doSaveAndAddNew').click();
			}
			</c:when>
			<c:otherwise>
			$('#sixFiveSeventyVerify').prop('checked', false);
			$('#doSaveAndAddNew').click();
			</c:otherwise>
		</c:choose>
		});
		if($('input[name="paymentTypeId"]').val()==1 || $('input[name="paymentTypeId"]').val()==2 || $('input[name="paymentTypeId"]').val()==4 || $('input[name="paymentTypeId"]').val()==6) {
			$('#printPaymentRequest').text('Print Payment Request Form');
			$('#printPaymentRequest').css('display','inline') 	;
		}
		else if($('input[name="paymentTypeId"]').val()== 3) {
			$('#printPaymentRequest').text('Print Partner Payment Request Form');
			$('#printPaymentRequest').css('display','inline');
		} else if($('input[name="paymentTypeId"]').val() == 5){
			$('#printPaymentRequest').text('Print Reclass Form');
			$('#printPaymentRequest').css('display','inline');
		} else {
			$('#printPaymentRequest').css('display','none');
		}

		$('#editPaymentrequestForm input, #editPaymentrequestForm select, #editPaymentrequestForm textarea').keypress(function(e) {
			if (e.keyCode == 9 || e.keyCode == 13) {// 9 - tab pressed, 13 - enter pressed
				e.preventDefault();
				var tabIndex = $(this).attr('tabindex');
				if (tabIndex == -1 && $(this).is('input[class^="payment-line-item-amount"]')) {
					var startIndex=("payment-line-item-amount").length;
					var index=parseInt(($(this).attr("class")).substring(startIndex));
					tabIndex = $('input[class^="formatted-payment-line-item-amount' + index + '"]').attr('tabindex');
				}
				tabIndex++;// increment tabindex
				var el = $('#editPaymentrequestForm').find('[tabindex=' + tabIndex + ']');
				if (el[0]) {
					el.focus();
				}

				return false;
			}
		});
	});
	
	function open6570VerifyDialog(okListener) {
		var ID_DIALOG_CONTAINER = 'test_ID_DIALOG_CONTAINER';

		var htmlString = '<div><input id="chk6570Verify" type="checkbox" />I verify that the deliverables have been received and accepted in accordance with the terms of the contract for this payment.</div>';
		var ui = $('<div id="' + ID_DIALOG_CONTAINER + '"></div>').append(htmlString);
		ui.dialog({
			modal: true,
			autoOpen : false,
			height: 250,
			width: 300,
			close: function(event, ui) {
				$(this).dialog('destroy');
			}
		});
		ui.dialog('option', 'buttons', {
			'OK' : function() {
				var verified = $('#chk6570Verify').prop('checked');
				$(this).dialog('close');
				$('#' + ID_DIALOG_CONTAINER).remove();
				if(okListener) {
					okListener(verified);
				}
			},
			'Cancel' : function() {
				$(this).dialog('close');
				$('#' + ID_DIALOG_CONTAINER).remove();
			}
		});
		ui.dialog('open');
	}
	
	<c:if test="${!empty paymentrequest.id && paymentrequest.id > 0}">
    	function toggleInputOrSelectElement(viewMode,elements) {
    		for(var i = 0; i < elements.length; i++) {
    			elements[i].readonly = viewMode;
    			var className = '';
    			if(viewMode) {
    				className = 'text_grey';
    				if(elements[i].className.indexOf("input-full-width-req") != -1) {
    					className = 'input-full-width-req ' + className;	
    				}else if(elements[i].className.indexOf("dhx_combo_input")!=-1)
    					className = className+' input-full-width-req ' ;	
    			} else {
    				if(elements[i].className.indexOf("input-full-width-req") != -1) {
    					className += 'input-full-width-req text_blue';	
    				} 
    				else {
    					className += 'text_white';
    				}
    			}
    			elements[i].className = className;
    		}
    	}
    	
    	function toggleButtons(viewMode, button) {
    		if(viewMode) {
    			button.attr('disabled','disabled');
    			button.removeClass('blue_btn');
    			button.addClass('gray_btn');
    		} else {
    			button.removeAttr('disabled');
    			button.removeClass('gray_btn');
    			button.addClass('blue_btn');
    		}
    	}
    	
    	function toggleViewEditMode(viewMode) {
    		var inputs = $('#paymentInfo input[type="text"]:not(.uneditable)');
    		var selects = $('#paymentInfo select:not(.uneditable)');
    		var textareas = $('#paymentInfo textarea:not(.uneditable)');
    		toggleInputOrSelectElement(viewMode,inputs);
    		toggleInputOrSelectElement(viewMode,selects);
    		toggleInputOrSelectElement(viewMode,textareas);
    		
    		if(viewMode)
    		{
    			z1.readonly(true,false);
    			z2.readonly(true,false);
    			z4.readonly(true,false);   
    			$("#receivedFromAccountingDate").datepicker("disable");
    			$("#invoiceRequestDate").datepicker("disable");
    			$("#dateToFinanace").datepicker("disable");
            	selects.each(function(){ 
            		$(this).attr("onfocus","this.initialSelect = this.selectedIndex;");
            		$(this).attr("onchange","this.selectedIndex = this.initialSelect;");       	
            	});
    		}else{
    			z1.readonly(false,true);
    			z2.readonly(false,true);
    			z4.readonly(false,true); 
    			selects.each(function(){ 
            		$(this).removeAttr("onfocus");
            		$(this).removeAttr("onchange");       	
            	});
    		}
    		toggleButtons(viewMode,$('#add-paymentrequest-link'));
    		toggleButtons(viewMode,$('#cancelEditButton'));
    		toggleButtons(viewMode,$('#save'));
    		toggleButtons(viewMode,$('#saveAndAddNew'));
    		toggleButtons(!viewMode,$('#editButton'));
			<c:if test="${showPaymentLineItems}">
    		var lineItemInputs = $('#paymentLineItems input');
    		var lineItemSelects = $('#paymentLineItems select');
    		for(var i = 0; i < lineItemInputs.length; i++) {
    			lineItemInputs[i].readonly = viewMode;
    			lineItemInputs[i].disabled = viewMode;
    		}
    		for(var i = 0; i < lineItemSelects.length; i++) {
    			lineItemSelects[i].readonly = viewMode;
    			lineItemSelects[i].disabled = viewMode;
    		}
			</c:if>
    	}
	</c:if>
	
		var z1 = dhtmlXComboFromSelect("paymentTypeId",274);
		z1.enableFilteringMode(true);
		z1.attachEvent("onChange",function(){
			if(z1.getSelectedValue()==1 || z1.getSelectedValue()==2 || z1.getSelectedValue()==4 || z1.getSelectedValue()==6) {
				$('#printPaymentRequest').text('Print Payment Request Form');
				$('#printPaymentRequest').css('display','inline');
			}
			else if(z1.getSelectedValue()== 3) {
				$('#printPaymentRequest').text('Print Partner Payment Request Form');
				$('#printPaymentRequest').css('display','inline');
			} else if(z1.getSelectedValue() == 5){
				$('#printPaymentRequest').text('Print Reclass Form');
				$('#printPaymentRequest').css('display','inline');
			} else {
				$('#printPaymentRequest').css('display','none');
			}

			if (z1.getSelectedValue() == 3 ? true : previousPaymentTypeId == 3) {
				var payeeId = "";
				var payeetype = "";
				if (z4.getSelectedValue() != '' && z4.getSelectedValue() != null) {
					payeeId = z4.getSelectedValue();
				}
				if (z1.getSelectedValue() == 3) {
					payeetype = "Partner";
				}

				loadDataViaAjax("getPayeeList.do", {
					"payeeId" : payeeId,
					"payeetype" : payeetype
				}, parsePayeeListJson);
			}
			previousPaymentTypeId = z1.getSelectedValue();
			
		});
		var previousPaymentTypeId = z1.getSelectedValue();
	    
	   var z2 = dhtmlXComboFromSelect("paymentMethod",274);
		z2.enableFilteringMode(true);		
		
		var z4 = dhtmlXComboFromSelect("payeeId",274);
		z4.enableFilteringMode(true);
		z4.attachEvent("onChange",function(){
			if (z4.getSelectedValue() != '') {
				$('#add-paymentrequest-link').val('Edit');
				$('#payeeDesc').val(z4.getSelectedText());
				loadDataViaAjax("getPayee.do", {
					"payeeId" : z4.getSelectedValue()
				}, function(bean) {
					$('#payeeAddress').val(bean.completeAddress);
				});
			} else {
				$('#add-paymentrequest-link').val('Add');
				$('#payeeDesc').val('');
				$('#payeeAddress').val('');
			}
		});
		$('.dhx_combo_input').focus(function(){
			 if($(this).val()=="Select")
				 $(this).val("");
		});

		z4.attachEvent("onBlur", function(){
				if (z4.getSelectedValue() != '' && z4.getSelectedValue() != null) {
					$('#add-paymentrequest-link').val('Edit');
					$('#payeeDesc').val(z4.getSelectedText());
					loadDataViaAjax("getPayee.do", {
						"payeeId" : z4.getSelectedValue()
					}, function(bean) {
						$('#payeeAddress').val(bean.completeAddress);
					});
				} else {
					$('#add-paymentrequest-link').val('Add');
					$('#payeeDesc').val('');
					$('#payeeAddress').val('');
				}
		  
		});

		function parsePayeeListJson(data) {
			var payeeId = z4.getSelectedValue();
			z4.clearAll();
			if (data) {
				var i = 0;
				var dataArr = new Array();
				for (p in data) {
					dataArr[i++] = [data[p], p];
				}

				z4.setComboValue("");
				z4.setComboText("Select");
				z4.addOption(dataArr, 274);
				z4.setComboValue(payeeId);
				/*for (p in data) {
					z4.addOption(data[p], p, 274);
					if(p == payeeId)			
						z4.setComboValue(p);
				}*/
			}
		}

</script>
<div id="editPaymentrequestDiv">
	<form:form name="editPaymentrequestForm" id="editPaymentrequestForm" cssClass="main_form" action="showAddPaymentrequest.do" method="post" modelAttribute="paymentrequest">
		<form:hidden path="id" />
        <form:checkbox id="sixFiveSeventyVerify" path="sixFiveSeventyVerify" cssClass="hiddenElement"/>
		<div class="form_head">
			<div class="floatL" style="padding-top:5px; width: 800px;">
				<a href="#" onclick="return false;" id="instructions-link" class="blue_btn"><spring:message code="editPaymentrequest.label.instructions" /></a>
				<a href="#" onclick="return false;" id="printWireForm" class="uneditable blue_btn"><spring:message code="editPaymentrequest.label.printWireForm" /></a>
                  <a href="#" onclick="return false;" id="newPaymentRequest" class="uneditable blue_btn"><spring:message code="editPaymentrequest.button.newPaymentRequest" /></a>
				<c:choose>
					<c:when test="${!empty paymentrequest.id && paymentrequest.id > 0}">
						<c:if test="${not empty allowedUiElements['Add Payment Request']['PROCESS PAYMENT button']}">
							<a class="blue_btn" id="processPayment" href="#" onclick="return false;">Process Payment</a>
						</c:if>	
					</c:when>
					<c:otherwise>
						<span class="gray_btn" href="#" onclick="return false;">Process Payment</span>
					</c:otherwise>
				</c:choose>
				<a class="blue_btn" id="printPaymentRequest" href="#" style="display: none;" onclick="return false;">&nbsp;</a>
			</div>			
    		<a href="#" class="close-button gray_btn floatR" tabindex="-1">Close Form</a><br class="clear" />
    	</div>
    	<div class="form_cont">
			<table id="paymentInfo" cellspacing="1" cellpadding="0" width="100%">
				<tr class="row">
					<td class="input-field" colspan="5" style="text-align: center;">
						<%@ include file="/common/messages.jsp" %>
					</td>
				</tr>
				<tr class="row">
					<td class="label2"><spring:message code="editPaymentrequest.label.paymentIdentifiedInformation" /></td>
					<td class="input-field">
						<form:input path="id" cssClass="uneditable input-full-width text_grey" readonly="true" tabindex="-1" style="font-size:2em"/>
						<form:errors path="id" cssClass="error" />
					</td>
					<td width="50">&nbsp;</td>
				</tr>
				<tr class="row">
					<td class="label2"><spring:message code="label.originator" /></td>
					<td class="input-field">
<%-- 				<input type="text" value="${paymentrequest.createdBy }" class="input-full-width text_grey uneditable" readonly="readonly" tabindex="-1" />  --%>
					<form:input path="createdBy" cssClass="uneditable input-full-width text_grey " readonly="true" tabindex="-1"/>
					</td>
					<td width="50">&nbsp;</td>
				</tr>
				<tr class="row">
					<td class="label2"><spring:message code="editPaymentrequest.label.dateEntered" /></td>
					<td class="input-field">
						<form:input readonly="true" path="creationDate" cssClass="uneditable input-full-width text_grey" tabindex="-1"/>
					</td>
					<td width="50">&nbsp;</td>
				</tr>
				<tr class="row">
					<td class="label2"><spring:message code="editPaymentrequest.label.statusCode" /></td>
					<td class="input-field">
						<input type="text" readonly="readonly" class="uneditable  text_grey" name="statusCode" maxlength="50" value="New" tabindex="-1"/>
						<form:errors path="statusCode" cssClass="error" />
					</td>
					<td width="50">&nbsp;</td>
				</tr>
                  <tr class="row">
                    <td class="label2"><spring:message code="editPaymentrequest.label.paymentrequesttype" /></td>
                    <td class="input-field">
                      <form:select path="paymentTypeId" id="paymentTypeId" cssClass="input-full-width-req text_blue" tabindex="1">
                             
                            <form:option value="" label="Select" />
                        <form:options items="${paymenttypeList}" itemValue="id" itemLabel="paymenttypename" />
                      </form:select>
                      <form:errors path="paymentTypeId" cssClass="error" />
                    </td>
                    <td width="50">&nbsp;</td>
                  </tr>
                  <tr class="row">
                    <td class="label2"><spring:message code="editPaymentrequest.label.paymentmethod" /></td>
                    <td class="input-field">
                      <form:select path="paymentMethod"  id ="paymentMethod" cssClass="input-full-width-req text_blue" tabindex="2">
                            <form:option value="" label="Select" />
                            <form:option value="Wire" label="Wire" />
                        <form:option value="Check" label="Check" />
                        <%-- Commented due to ERR-24 
                        <form:option value="Other" label="Other" />
                        --%>
                      </form:select>
                      <form:errors path="paymentMethod" cssClass="error" />
                    </td>
                    <td width="50">&nbsp;</td>
                  </tr>
				<tr class="row">
					<td  width="35%" class="label2"><spring:message code="editPaymentrequest.label.payee" /></td>
					<td  width="18%" class="input-field" nowrap="nowrap">
						<form:select path="payeeId" id="payeeId" cssClass="input-full-width-req text_blue" tabindex="3">
					    	<form:option value="" label="Select" />
							<form:options items="${payeeList}" itemValue="id" itemLabel="payeeName" />
						</form:select> 
					</td>
					<td  width="35%">
						<c:if test="${not empty allowedUiElements['Payee - Add']['Add/Edit button']}">
							<sj:submit id="add-paymentrequest-link" nameKey="editPaymentrequest.button.addEditPayee" cssClass="blue_btn cancel" target="editPaymentrequestDiv" key="paymentrequestlist.table.link.add" tabindex="-1"/>
						</c:if>
						<form:hidden path="payeeDesc"/>
						<form:errors path="payeeId" cssClass="error" /></td>
				</tr>
				<tr class="row">
					<td class="label2"><spring:message code="editPaymentrequest.label.payeeAddress" /></td>
					<td class="input-field">
						<input id="payeeAddress" class="text_grey uneditable" readonly="readonly" tabindex="-1"/>
					</td>
					<td width="50">&nbsp;</td>
				</tr>
                  <tr class="row">
                    <td class="label2">Source Document Type</td>
                    <td class="input-field">
                        <form:select path="sourceDocumentType"  id ="sourceDocumentType" cssClass="input-full-width text_white" tabindex="4">
                            <form:option value="Invoice" label="Invoice" />
                            <form:option value="Account" label="Account" />
                            <form:option value="Contract" label="Contract" />
                            <form:option value="Reference #" label="Reference #" />
                        </form:select>
                    </td>
                    <td width="50">&nbsp;</td>
                  </tr>
				<tr class="row">
					<td class="label2"><spring:message code="editPaymentrequest.label.invoiceno" /></td>
					<td class="input-field">
						<form:input path="invoicenumber" maxlength="255" cssClass="input-full-width text_white" tabindex="5"/>
						<form:errors path="invoicenumber" cssClass="error" />
					</td>
					<td width="50">&nbsp;</td>
				</tr>
				<tr class="row">
					<td class="label2"><spring:message code="editPaymentrequest.label.invoiceRequestDate" /></td>
					<td class="input-field">
						<form:input path="invoiceRequestDate" cssClass="input-full-width text_white" tabindex="6"/>
						<form:errors path="invoiceRequestDate" cssClass="error" />
					</td>
					<td width="50">&nbsp;</td>
				</tr>
				<tr class="row">
					<td class="label2"><spring:message code="editPaymentrequest.label.purposeOfExpenditure" /></td>
					<td class="input-field">
						<form:input path="purposeOfExpenditure" maxlength="500" cssClass="input-full-width-req text_blue" tabindex="7"/>
						<form:errors path="purposeOfExpenditure" cssClass="error" />
					</td>
					<td width="50">&nbsp;</td>
				</tr>
				<tr class="row">
					<td class="label2"><spring:message code="editPaymentrequest.label.specialInstructions" /></td>
					<td class="input-field">
						<form:input path="specialInstructions" maxlength="200" cssClass="input-full-width text_white" tabindex="8"/>
						<form:errors path="specialInstructions" cssClass="error" />
					</td>
					<td width="50">&nbsp;</td>
				</tr>
				<tr class="row">
					<td class="label2"><spring:message code="editPaymentrequest.label.amount" /></td>
					<td class="input-field">
						<form:hidden path="amount" cssClass="input-full-width text_grey" />
						<input type="text" value="&nbsp;" readonly="readonly"  id="amountLabel" class="uneditable input-full-width-req text_grey" tabindex="-1" style="font-size: 2em"/>
						<form:errors path="amount" cssClass="error" />
					</td>
					<td width="50">&nbsp;</td>
				</tr>
				<tr>
	                <td align="right">&nbsp;</td>
	                <td>&nbsp;</td>
	                <td width="50">&nbsp;</td>
	                <td align="right">&nbsp;</td>
	              	<td></td>
	           	</tr>
			</table>
			<c:if test="${showPaymentLineItems}">
			<div id="paymentLineItems">&nbsp;</div>
			</c:if>
              <div style="text-align: center;">
                  <c:if test="${!empty paymentrequest.id && paymentrequest.id > 0}">
                    <input id="editButton" type="button" class="blue_btn" value="Edit">
                    <input id="cancelEditButton" type="button" class="gray_btn" value="Cancel Edit">
                  </c:if>
                  <input id="save" type="button" class="blue_btn" value='<spring:message code="editPaymentrequest.button.save" />' tabindex="-1"/>
                  <input id="saveAndAddNew" type="button" class="blue_btn" value='<spring:message code="editPaymentrequest.button.saveAndAddNew" />' tabindex="-1"/>
                  <sj:submit id="doSave" cssClass="hiddenSubmitButton" target="editPaymentrequestDiv" key="editPaymentrequest.button.save" validate="true" tabindex="-1"/>
                  <sj:submit id="doSaveAndAddNew" cssClass="hiddenSubmitButton" target="editPaymentrequestDiv" key="editPaymentrequest.button.saveAndAddNew" validate="true" tabindex="-1"/>                
              </div>
		</div>
		<br class="clear" />
	</form:form>
</div>
